﻿using System.Web;
using NHibernate;

namespace Lyh.Core.Storage
{
    public class HttpSessionStorage : ISessionStorage
    {
        private const string CurrentSessionKey = "nhibernate.current_session";

        public ISession Get()
        {
            if (HttpContext.Current == null) return null;
            return (ISession) HttpContext.Current.Items[CurrentSessionKey];
        }

        public void Set(ISession value)
        {
            if (HttpContext.Current != null && value != null)
            {
                HttpContext.Current.Items.Add(CurrentSessionKey, value);
            }
        }

    }
}